<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">

      <template #large_image="{ record }">
        <a-image
    width="100"
    :src="record.large_image"
  />

      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import systemDeviceImg from '@/api/system/systemDeviceImg'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'

const crudRef = ref()


const numberOperation = (newValue, id, numberName) => {
  systemDeviceImg.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  systemDeviceImg.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  beforeRequest: params => {
        params.orderBy = 'id'
        // 指定降序排序
        params.orderType = 'desc'

  },
  id: 'system_device_img',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: systemDeviceImg.getList,
  recycleApi: systemDeviceImg.getRecycleList,
  add: {
    show: false,
    api: systemDeviceImg.save,
    auth: ['system:deviceImg:save']
  },
  edit: {
    show: false,
    api: systemDeviceImg.update,
    auth: ['system:deviceImg:update']
  },
  delete: {
    show: true,
    api: systemDeviceImg.deletes,
    auth: ['system:deviceImg:delete'],
    realApi: systemDeviceImg.realDeletes,
    realAuth: ['system:deviceImg:realDeletes']
  },
  recovery: {
    show: true,
    api: systemDeviceImg.recoverys,
    auth: ['system:deviceImg:recovery']
  },
  import: {
    show: true,
    url: 'system/deviceImg/import',
    templateUrl: 'system/deviceImg/downloadTemplate',
    auth: ['system:deviceImg:import']
  },
  export: {
    show: true,
    url: 'system/deviceImg/export',
    auth: ['system:deviceImg:export']
  }
})

const columns = reactive([
  {
    title: "",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    commonRules: {
      required: true,
      message: "请输入"
    }
  },
  {
    title: "设备名称",
    dataIndex: "device_name",
    formType: "input"
  },
  {
    title: "设备码",
    dataIndex: "device_code",
    formType: "input",
    search: true
  },
  {
    title: "采集大图",
    dataIndex: "large_image",
    formType: "input"
  },
  {
    title: "采集日期",
    dataIndex: "datetime",
    formType: "input"
  },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "更新时间",
    dataIndex: "updated_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "软删除字段",
    dataIndex: "deleted_at",
    formType: "date",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    showTime: true
  },
  {
    title: "性别",
    dataIndex: "gender",
    formType: "input"
  },
  {
    title: "年龄范围",
    dataIndex: "age",
    formType: "input"
  },
  {
    title: "头像图片集",
    dataIndex: "images",
    formType: "upload",
    hide: true,
    type: "image",
    multiple: true
  },
  {
    title: "数据id",
    dataIndex: "device_id",
    formType: "input",
    search: false
  }
])
</script>
<script> export default { name: 'system:deviceImg' } </script>